<?php

// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 前台产品控制器
 * 
 */
class ProductController extends HomeController {

    //系统首页
    public function index() {
        $tid = I("type",0,'intval');
        $type = D("ProductType")->field(true)->order("sort")->limit(4)->select();
        if(empty($tid)){
            $tid =$type[0]["id"];
        }
        $where["tid"] = array("eq",$tid);
        $product = D("Product")->field("id,pname,pic,explain")->where($where)->select();
        foreach ($product as $key => $value) {
            if ($value["pic"] != null) {
                $pic = explode(",", $value["pic"]);
                $product[$key]["pic"] = $pic[0];
            }
        }
        $this->assign("type", $type);
        $this->assign("product", $product);
        $this->display();
    }
    
    public function detail(){
        $tid = I("type",0,'intval');
        $type = D("ProductType")->field(true)->order("sort")->limit(4)->select();
        $id = I("id",0,'intval');
        if(!empty($id)){
             $where["id"] =array("eq",$id);
        }
        $info = D("Product")->where($where)->field(true)->find();
        $this->assign("type", $type);
        $this->assign("info", $info);
        $this->display();
    }

}
